import { getBaseUrl } from '@/services/urlconst';
import { requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';

let baseUrl = getBaseUrl();

/**
 * 添加流程条件
 * @param addConditionCallback
 * @returns
 */
const addConditionService = (addConditionCallback: (res: any) => void) => {
  const addCondition = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/activitiController/addCondition`;
      let bodyParams = {
        ...params,
      };
      return requestFunComponFiex('POST', personUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: addConditionCallback,
    },
  );

  return {
    addConditionRun: addCondition?.run,
    addConditionLoading: addCondition?.loading,
  };
};

/**
 * 编辑流程条件
 * @param editConditionCallback
 * @returns
 */
const editConditionService = (editConditionCallback: (res: any) => void) => {
  const editCondition = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/activitiController/editCondition`;
      let bodyParams = {
        ...params,
      };
      return requestFunComponFiex('PUT', personUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: editConditionCallback,
    },
  );

  return {
    editConditionRun: editCondition?.run,
    editConditionLoading: editCondition?.loading,
  };
};

export { addConditionService, editConditionService };
